home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / gestalt.zip / SIMIL_P.OBJ < prev   
Text File  |  1988-12-06  |  17KB  |  259 lines

  1. Inline(
  2.                          {;From the article "Pattern Matching - The Gestalt Approach"}
  3.                          {;by John W. Ratcliff and David E. Metzener}
  4.                          {;Dr. Dobbs Journal, July 1988}
  5.                          {;Rewritten for Turbo Pascal v3.0 inline code and INLINE.COM.}
  6.                          {;Now expects normal Pascal strings (first byte is length byte).}
  7.                          {;Usage:}
  8.                          {;}
  9.                          {;FUNCTION Simil(VAR Str1,Str2) : INTEGER;}
  10.                          {;  VAR  result : INTEGER;}
  11.                          {;  BEGIN}
  12.                          {;    (*$I simil_p.obj*)    (* this code *)}
  13.                          {;    Simil := result;  (*return the function result*)}
  14.                          {;  END;  (* of Simil *)}
  15.                          {;}
  16.                          {;See TESTSIM.PAS for required global variables.}
  17.                          {;}
  18.                          {;Extensive remarks removed.  See other versions.}
  19.                          {; David Kirschbaum}
  20.                          {; Toad Hall}
  21.                          {; kirsch@braggvax.ARPA}
  22.   $55                    {  push  bp              ;save Turbo's BP}
  23.   /$06                   {  push  ES              ;and ES}
  24.   /$FC                   {  cld                   ;insure forward}
  25.   /$C4/$B6/>STR1         {  les   si,>str1[bp]    ;ES:SI = str1 addr}
  26.   /$8B/$BE/>STR2         {  mov   di,>str2[bp]    ;ES:DI = str2 addr}
  27.                          {;}
  28.   /$31/$C0               {  xor   ax,ax           ;get a 0}
  29.   /$A3/>SCORE            {  mov   [>score],ax     ;zero out SCORE}
  30.   /$A3/>STCKNUM          {  mov   [>stcknum],ax   ;init nr of stack entries to 0}
  31.   /$26                   {  ES:}
  32.   /$38/$04               {  cmp   [si],al         ;is it a null string?}
  33.   /$74/$05               {  je    StrErr          ;can't process null strings}
  34.   /$26                   {   ES:}
  35.   /$38/$05               {   cmp  [di],al         ;is it a null string?}
  36.   /$75/$03               {   jne  DoCmp           ;Both strs ok, so process them}
  37.                          {StrErr:}
  38.   /$E9/$4E/$01           {  jmp   Exit            ;exit routine}
  39.                          {;}
  40.                          {DoCmp:}
  41.   /$30/$E4               {  xor   ah,ah           ;clear msb}
  42.   /$26                   {  ES:}
  43.   /$8A/$04               {  mov   al,[si]         ;get str1 length byte}
  44.   /$89/$C1               {  mov   cx,ax           ;accum total len in CX}
  45.   /$01/$F0               {  add   ax,si           ;add in string start}
  46.   /$89/$C3               {  mov   bx,ax           ;BX points to str1 last char}
  47.   /$46                   {  inc   si              ;bump SI past str1 length byte}
  48.                          {;}
  49.   /$30/$E4               {  xor   ah,ah           ;clear msb}
  50.   /$26                   {  ES:}
  51.   /$8A/$05               {  mov   al,[di]         ;str2 length byte}
  52.   /$01/$C1               {  add   cx,ax           ;accum total len in CX}
  53.   /$01/$F8               {  add   ax,di           ;add in start}
  54.   /$89/$C5               {  mov   bp,ax           ;BP points to str2 last char}
  55.   /$47                   {  inc   di              ;bump DI past str2 length byte}
  56.                          {;}
  57.   /$89/$0E/>TOTAL        {  mov   [>total],cx     ;store total string length}
  58.                          {;}
  59.   /$E8/$ED/$00           {  call  PushSt          ;push values for}
  60.                          {;                        ; first call to SIMILIARITY}
  61.                          {Main:}
  62.   /$81/$3E/>STCKNUM/$00/$00{  cmp   word [>stcknum],0 ;anything on the stack?}
  63.   /$74/$76               {  je    Done            ;no, then all done!}
  64.                          {;}
  65.   /$E8/$05/$01           {  call  PopSt           ;get regs set up for a compare call}
  66.   /$E8/$85/$00           {  call  Compare         ;do compare for this substring set}
  67.   /$09/$D2               {  or    dx,dx           ;if nothing in common}
  68.                          {                        ; then nothing to push}
  69.   /$74/$EE               {  jz    Main            ;try another set}
  70.                          {;}
  71.   /$D1/$E2               {  shl   dx,1              ;*2}
  72.   /$01/$16/>SCORE        {  add   [>score],dx       ;add into score}
  73.   /$8B/$2E/>STCKNUM      {  mov   bp,[>stcknum]     ;get nr of entry}
  74.                          {                          ; I want to look at}
  75.   /$D1/$E5               {  shl   bp,1              ;get AX ready}
  76.                          {                          ; to access string stacks}
  77.   /$3E                   {  DS:                     ;override SS:bp}
  78.   /$8B/$B6/>STSTR1L      {  mov   si,[>ststr1L][bp] ;move L1 into SI or L1}
  79.   /$8B/$1E/>CL1          {  mov   bx,[>cL1]         ;move CL1 into BX or R1}
  80.   /$3E                   {  DS:                     ;override SS:bp}
  81.   /$8B/$BE/>STSTR2L      {  mov   di,[>ststr2L][bp] ;move L2 into DI or L2}
  82.   /$8B/$0E/>CL2          {  mov   cx,[>cL2]         ;move CL2 into CX temporarily}
  83.   /$3E                   {  DS:                     ;override SS:bp}
  84.   /$8B/$86/>STSTR1R      {  mov   ax,[>ststr1R][bp] ;get old R1 off of stack}
  85.   /$A3/>CL1              {  mov   [>cL1],ax         ;place in CL1 temporarily}
  86.   /$3E                   {  DS:                     ;override SS:bp}
  87.   /$8B/$86/>STSTR2R      {  mov   ax,[>ststr2R][bp] ;get old R2 off of stack}
  88.   /$A3/>CL2              {  mov   [>cL2],ax         ;save in CL2 temporarily}
  89.   /$89/$CD               {  mov   bp,cx             ;place CL2 into BP}
  90.                          {;}
  91.   /$39/$F3               {  cmp   bx,si           ;compare CL1 to L1}
  92.   /$74/$11               {  je    Chrght          ;if zero, then nothing}
  93.                          {;                       ; on left side str1}
  94.   /$39/$FD               {  cmp   bp,di           ;compare CL2 to L2}
  95.   /$74/$0D               {  je    Chrght          ;if zero, then nothing}
  96.                          {;                       ; on left side str2}
  97.   /$4B                   {  dec   bx              ;point to last part}
  98.                          {                        ; of left side str1}
  99.   /$4D                   {  dec   bp              ;ditto, str2}
  100.   /$39/$F3               {  cmp   bx,si           ;only one char to examine?}
  101.   /$75/$04               {  jne   PushIt          ;no->we need to examine this}
  102.   /$39/$FD               {   cmp  bp,di           ; only one char in both?}
  103.   /$74/$03               {   je   Chrght          ;  nothing to look at}
  104.                          {;                       ;  if both only contain 1 char}
  105.                          {PushIt:}
  106.   /$E8/$96/$00           {  call  PushSt          ;push left side on stack}
  107.                          {Chrght:}
  108.   /$8B/$36/>CR1          {  mov   si,[>cR1]       ;move CR1 into SI or L1}
  109.   /$8B/$1E/>CL1          {  mov   bx,[>cL1]       ;move R1 into BX or R1}
  110.   /$8B/$3E/>CR2          {  mov   di,[>cR2]       ;move CR2 into DI or L2}
  111.   /$8B/$2E/>CL2          {  mov   bp,[>cL2]       ;move R2 into BP or R2}
  112.                          {;}
  113.   /$39/$DE               {  cmp   si,bx           ;compare CR1 to R1}
  114.   /$74/$95               {  je    Main            ;If zero, then nothing}
  115.                          {                        ; on right side str1}
  116.   /$39/$EF               {  cmp   di,bp           ;compare CR2 to R2}
  117.   /$74/$91               {  je    Main            ;if zero, then nothing}
  118.                          {                        ; on right side str2}
  119.   /$46                   {  inc   si              ;point to last part}
  120.                          {                        ; of right side str1}
  121.   /$47                   {  inc   di              ;ditto, str2}
  122.   /$39/$F3               {  cmp   bx,si           ;only one char to examine?}
  123.   /$75/$04               {  jne   Push2           ;no-> examine it}
  124.   /$39/$FD               {   cmp  bp,di           ; only 1 char to examine in both?}
  125.   /$74/$87               {   je   Main            ; yes-> get next string off of stack}
  126.                          {;}
  127.